package chapter07

import scala.collection.mutable

/**
 * Map集合
 * 可变Map
 */
object Test09_MutableMap {
  def main(args: Array[String]): Unit = {
    //1、创建Map
    val map1: mutable.Map[String, Int] = mutable.Map("a" -> 13, "b" -> 53, "hello" -> 23)
    println(map1)
    println(map1.getClass)

    println("=============================")
    //2、添加元素
    map1.put("c", 5)
    map1.put("d", 6)
    println(map1)

    map1 += (("e", 7))
    println(map1)

    println("=============================")

    //3、删除元素
    println(map1("c"))
    map1.remove("c")
    println(map1)
    println(map1.getOrElse("c", 0))


    //4、修改元素
    println("===========4、修改元素==================")
    map1.update("c", 5)
    map1.update("e", 10)
    println(map1)

    map1 += (("e", 7))
    println(map1)


    println("=============================")
    val map2: Map[String, Int] = Map("aaa" -> 11, "b" -> 29, "hello" -> 5)
    map1 ++= map2
    println(map1)
    println(map2)

    println("-------------------------------")
    val map3: Map[String, Int] = map2 ++ map1
    println(map1)
    println(map2)
    println(map3)
  }
}
